import simplejson

INVALID_LAT_OR_LON = 1;
SERVICE_UNAVAILABLE = 2;

ERR_MSG = {
            INVALID_LAT_OR_LON: "Specified latitude or longitude is invalid",
            SERVICE_UNAVAILABLE: "Failed to acquire service"
	  }

class Error:
  def __init__(self, code, details, http_status_code):
    self.code = code
    self.msg = ERR_MSG.get(code, "Unknown error")
    self.details = details
    self.http_status_code = http_status_code


  def send(self, response):
    response.set_status(self.http_status_code)
    response.out.write(self)

  def __repr__(self):
    return simplejson.dumps({'error': {'code': self.code, 'message': self.msg, 'details': self.details}}, indent=4)

def error(code, details, http_status_code=400):
  return Error(code, details, http_status_code)

